home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / database / sdbio.h < prev    next >
Text File  |  1985-06-28  |  8KB  |  212 lines

  1. /* SDB - definition file */
  2. #define Lattice
  3. /* useful definitions */
  4. #define TRUE            1
  5. #define FALSE           0
  6. #ifndef NULL
  7. #define NULL            0
  8. #endif
  9.  
  10. /* program limits */
  11. #define LINEMAX         132     /* maximum input line length */
  12. #define TABLEMAX        132     /* maximum table output line */
  13. #define KEYWORDMAX      10      /* maximum keyword length */
  14. #define NUMBERMAX       20      /* maximum number length */
  15. #define STRINGMAX       132     /* maximum string length */
  16. #define CODEMAX         100     /* maximum length of code array */
  17. #define STACKMAX        20      /* maximum interpreter stack size */
  18.  
  19. /* token definitions */
  20. #define EOS             0
  21. #define LSS             -1
  22. #define LEQ             -2
  23. #define EQL             -3
  24. #define NEQ             -4
  25. #define GEQ             -5
  26. #define GTR             -6
  27. #define SELECT          -7
  28. #define FROM            -8
  29. #define WHERE           -9
  30. #define CREATE          -10
  31. #define DELETE          -11
  32. #define INSERT          -12
  33. #define EXIT            -13
  34. #define CHAR            -14
  35. #define NUM             -15
  36. #define ID              -16
  37. #define STRING          -17
  38. #define NUMBER          -18
  39. #define UPDATE          -19
  40. #define PRINT           -20
  41. #define IMPORT          -21
  42. #define EXPORT          -22
  43. #define INTO            -23
  44. #define HELP            -24
  45. #define COMPRESS        -25
  46. #define EXTRACT         -26
  47. #define DEFINE          -27
  48. #define SHOW            -28
  49. #define USING           -29
  50. #define SORT            -30
  51. #define BY              -31
  52. #define ASCENDING       -32
  53. #define DESCENDING      -33
  54. #define SET             -34
  55.  
  56. /* operand types */
  57. #define LITERAL 1
  58. #define ATTR    2
  59. #define TEMP    3
  60.  
  61. /* attribute data types */
  62. #define TCHAR   1
  63. #define TNUM    2
  64.  
  65. /* tuple status codes */
  66. #define UNUSED  0
  67. #define ACTIVE  1
  68. #define DELETED 2
  69.  
  70. /* relation header page format definitions */
  71. #define RNSIZE          10      /* size of a relation name */
  72. #define HSIZE           16      /* size of a relation entry */
  73. #define ASIZE           16      /* size of a attribute entry */
  74. #define ANSIZE          10      /* size of a attribute name */
  75. #define NATTRS          31      /* number of attributes in header block */
  76.  
  77. /* error code definitions */
  78. #define END             0       /* end of retrieval set */
  79. #define INSMEM          1       /* insufficient memory */
  80. #define RELFNF          2       /* relation file not found */
  81. #define BADHDR          3       /* bad relation file header */
  82. #define TUPINP          4       /* tuple input error */
  83. #define TUPOUT          5       /* tuple output error */
  84. #define RELFUL          6       /* relation file full */
  85. #define RELCRE          7       /* error creating relation file */
  86. #define DUPATT          8       /* duplicate attribute on relation create */
  87. #define MAXATT          9       /* too many attributes on relation create */
  88. #define INSBLK          10      /* insufficient disk blocks */
  89. #define SYNTAX          11      /* command syntax error */
  90. #define ATUNDF          12      /* attribute name undefined */
  91. #define ATAMBG          13      /* attribute name ambiguous */
  92. #define RLUNDF          14      /* relation name undefined */
  93. #define CDSIZE          15      /* boolean expression code too big */
  94. #define INPFNF          16      /* input file not found */
  95. #define OUTCRE          17      /* output file creation error */
  96. #define INDFNF          18      /* indirect command file not found */
  97. #define BADSET          19      /* bad set parameter */
  98.  
  99. struct attribute {
  100.     char at_name[ANSIZE];       /* attribute name */
  101.     char at_type;               /* attribute type */
  102.     char at_size;               /* attribute size in bytes */
  103.     char at_scale;              /* attribute scale factor (for numeric only) */
  104.     char at_unused[ASIZE-ANSIZE-3];     /* unused space */
  105. };
  106.  
  107. struct header {         /* sizeof(struct header) must be 512 bytes */
  108.     char hd_tcnt[2];            /* # of tuples in relation */
  109.     char hd_tmax[2];            /* maximum # of tuples */
  110.     char hd_data[2];            /* offset to first data byte */
  111.     char hd_size[2];            /* size of each tuple in bytes */
  112.     char hd_unused[HSIZE-8];    /* unused space */
  113.     struct attribute hd_attrs[NATTRS];  /* table of attributes */
  114. };
  115.  
  116. struct relation {
  117.     char rl_name[RNSIZE];       /* relation name */
  118.     unsigned int rl_tcnt;       /* # of tuples in relation (from hd_tcnt) */
  119.     unsigned int rl_tmax;       /* maximum # of tuples (from hd_tmax) */
  120.     int rl_data;                /* offset to first data byte (from hd_data) */
  121.     int rl_size;                /* size of eachtuple in bytes (from hd_size) */
  122.     int rl_store;               /* flag indicating a store happened */
  123.     int rl_fd;                  /* file descriptor for relation file */
  124.     int rl_scnref;              /* number of scans referencing this relation */
  125.     struct header rl_header;    /* the relation file header block */
  126.     struct relation *rl_next;   /* pointer to next relation */
  127. };
  128.  
  129. struct scan {
  130.     struct relation *sc_relation;       /* pointer to relation definition */
  131.     unsigned int sc_dtnum;              /* desired tuple number */
  132.     unsigned int sc_atnum;              /* actual tuple number */
  133.     int sc_store;                       /* flag indicating a store happened */
  134.     char *sc_tuple;                     /* tuple buffer */
  135. };
  136.  
  137. struct srel {
  138.     char *sr_name;                      /* alternate relation name */
  139.     struct scan *sr_scan;               /* relation scan structure ptr */
  140.     int sr_ctuple;                      /* current tuple flag */
  141.     int sr_update;                      /* updated tuple flag */
  142.     struct srel *sr_next;               /* next selected relation in list */
  143. };
  144.  
  145. struct sattr {
  146.     char *sa_rname;                     /* relation name */
  147.     char *sa_aname;                     /* attribute name */
  148.     char *sa_name;                      /* alternate attribute name */
  149.     char *sa_aptr;                      /* pointer to attr in tuple buffer */
  150.     struct srel *sa_srel;               /* pointer to the selected relation */
  151.     struct attribute *sa_attr;          /* attribute structure ptr */
  152.     struct sattr *sa_next;              /* next selected attribute in list */
  153. };
  154.  
  155. struct operand {
  156.     int o_type;
  157.     union  {
  158.         struct {
  159.             int ovc_type;
  160.             char *ovc_string;
  161.             int ovc_length;
  162.         } ov_char;
  163.         int ov_boolean;
  164.     } o_value;
  165. };
  166.  
  167. union codecell {
  168.     int (*c_operator)();
  169.     struct operand *c_operand;
  170. };
  171.  
  172. struct binding {
  173.     struct attribute *bd_attr;          /* bound attribute */
  174.     char *bd_vtuple;                    /* pointer to value in tuple */
  175.     char *bd_vuser;                     /* pointer to user buffer */
  176.     struct binding *bd_next;            /* next binding */
  177. };
  178.  
  179. struct sel {
  180.     struct srel *sl_rels;               /* selected relations */
  181.     struct sattr *sl_attrs;             /* selected attributes */
  182.     union codecell *sl_where;           /* where clause */
  183.     struct binding *sl_bindings;        /* user variable bindings */
  184. };
  185.  
  186. struct mtext {
  187.     char *mt_text;
  188.     struct mtext *mt_next;
  189. };
  190.  
  191. struct macro {
  192.     char *mc_name;
  193.     struct mtext *mc_mtext;
  194.     struct macro *mc_next;
  195. };
  196.  
  197. struct ifile {
  198.     char *if_fp;
  199.     struct mtext *if_mtext;
  200.     char *if_cmdline;
  201.     int if_savech;
  202.     char *if_lptr;
  203.     struct ifile *if_next;
  204. };
  205.  
  206. struct skey {
  207.     int sk_type;
  208.     struct attribute *sk_aptr;
  209.     int sk_start;
  210.     struct skey *sk_next;
  211. };
  212.